package com.ruoyi.web.controller.training;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.domain.ExamRes;
import com.ruoyi.training.service.IExamResService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员做题记录持久化(考核记录)Controller
 *
 * @author wng
 * @date 2024-08-04
 */
@RestController
@RequestMapping("/training/examRes")
public class ExamResController extends BaseController {
    @Resource
    private IExamResService examResService;

    /**
     * 查询人员做题记录持久化(考核记录)列表
     */
    @PreAuthorize("@ss.hasPermi('system:res:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamRes examRes) {
        startPage();
        List<ExamRes> list = examResService.selectExamResList(examRes);
        return getDataTable(list);
    }

    /**
     * 导出人员做题记录持久化(考核记录)列表
     */
    @PreAuthorize("@ss.hasPermi('system:res:export')")
    @Log(title = "人员做题记录持久化(考核记录)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamRes examRes) {
        List<ExamRes> list = examResService.selectExamResList(examRes);
        ExcelUtil<ExamRes> util = new ExcelUtil<ExamRes>(ExamRes.class);
        util.exportExcel(response, list, "人员做题记录持久化(考核记录)数据");
    }

    /**
     * 获取人员做题记录持久化(考核记录)详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:res:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(examResService.selectExamResById(id));
    }

    /**
     * 新增人员做题记录持久化(考核记录)
     */
    @PreAuthorize("@ss.hasPermi('system:res:add')")
    @Log(title = "人员做题记录持久化(考核记录)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamRes examRes) {
        return toAjax(examResService.insertExamRes(examRes));
    }

    /**
     * 修改人员做题记录持久化(考核记录)
     */
    @PreAuthorize("@ss.hasPermi('system:res:edit')")
    @Log(title = "人员做题记录持久化(考核记录)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamRes examRes) {
        return toAjax(examResService.updateExamRes(examRes));
    }

    /**
     * 删除人员做题记录持久化(考核记录)
     */
    @PreAuthorize("@ss.hasPermi('system:res:remove')")
    @Log(title = "人员做题记录持久化(考核记录)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examResService.deleteExamResByIds(ids));
    }
}
